/*************************************************************************
	> File Name: ObjectOutpuStreamTest.java
	> Author: Potter
	> Mail: tobewhatwewant@gmail.com 
	> Created Time: 2014年06月02日 星期一 01时54分27秒
 ************************************************************************/
import java.io.*;

public class ObjectOutpuInputStreamTest {
    public static void main(String[] args) throws Exception {
        write();
        read();
    }

    static void write() throws Exception {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("tmp.txt"));
        Person per = new Person(1, "Potter", 20, "asd@!!$");
        oos.writeObject(per);
    }

    static void read() throws Exception {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("tmp.txt"));
        Person per = (Person)ois.readObject();
        System.out.println(per); 
    }
}

class Person implements Serializable {
    private int id;
    private String name;
    private int age;

    private transient String cardpassword;

    public void setCardpassword(String cp) {
        this.cardpassword = cp;
    }

    public String getCardpassword() {
        return cardpassword;
    }

    public String toString() {
        return id+" : "+name+" : "+age+" : "+cardpassword;    
    }

    public Person(int id, String name, int age, String cardpassword) {
        super();
        this.id = id;
        this.name = name;
        this.age = age;
        this.cardpassword = cardpassword;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getAge() {
        return age;
    }
}

